﻿@{
    ViewBag.Title = "MaterialProductModeMaterialAdd";
    Layout = "~/Views/Shared/NonFilterLayout.cshtml";
}

@{
    var action = ViewData["action"].ToString();
    string Id = ViewData["Id"].ToString();
}

<div class="mod_info" id="idmod_info" style="background-color:white;height:100%">
    <div class="mod_detail">
        <div class="hd" id="idhd">
            <span style="font-size:20px">&nbsp;&nbsp;&nbsp;&nbsp;物料列表</span>
        </div>
        <div class="bd">
            <div class="func_box" id="divBox">
                <div class="inpt_box">
                    <input id="txtSearchContains" type="text" placeholder="请输入物料规格/物料代码" />
                </div>
                <div class="btn_box">
                    <button id="btnSearch" style="width:120px" class="btn_green_m"><i class="ico ico_bsearch"></i>搜索</button>
                    <a class="btn_add" id="btnAdd" style="width:120px;display:none" data-type="user" href="javascript:;"><i class="ico ico_badd"></i>新增</a>
                </div>
            </div>
            <table id="infoList"></table>
        </div>
        <div class="fd" id="idfd">
            <div class="load_btn">
                <button class="btn_green_m" id="btnSave">选  择</button>
                <button class="btn_gray_m" id="btnCancel">取  消</button>

            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        var height = $("#idmod_info").height();
        var hd = $("#idhd").height();
        var divBox = $("#divBox").height();
        var fd = $("#idfd").height();
        var content = parseFloat(height) - parseFloat(hd) - parseFloat(divBox) - parseFloat(fd)-150;
        $("#infoList").css("height", content);
    });
</script>
<script>
    $(function () {
        $("#infoList").datagrid({
            url: '/Setting/GetProductModeMaterialListById',
            loadMsg: '数据加载中请稍后……',
            idField: "ID",
            nowrap: false,
            fitColumns: true,
            pageSize: 100,
            pageList: [20, 50, 100],
            pagination: true,
            columns: [[
                  { field: 'M_CODE', title: '物料代码', width: "10%", align: "center" }
                , { field: 'M_SPECIFICATION', title: '物料型号', width: "19%", align: "left" }
                , { field: 'M_COMPANY', title: '厂家', width: "10%", align: "center" }
                , { field: 'M_TYPE', title: '类型', width: "10%", align: "center" }
            ]]
        });

        $("#btnSave").click(function () {
            var rowData = $("#infoList").datagrid("getSelected");
            if (rowData) {
                if ("@action" == "add") {
                    com.ajax({
                        url: "/Resource/AddSupplier",
                        data: { supplierId: rowData.COMPANY_ID },
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.state == "success") {
                                parent.$("#infoList").datagrid("load");
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            }
                            else {
                                layer.alert(data.msg);
                            }

                        }
                    });
                }
            }
            else {

                layer.alert("请选择一条记录！");
            }
        });
    });

    $("#btnAdd").click(function () {
        var index = layer.open({
            anim: -1,
            title: !1,
            closeBtn: !1,
            type: 2,
            shadeClose: false,
            area: ['403px', '410px'],
            move: false,
            content: ['/Setting/CompanyInfoEdit?width=-205px&action=add&Id=0', 'no']
        })
        return false;
    });

    $("#btnCancel").click(function () {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
        return false;
    });

    $("#btnSearch").click(function () {
        var target = $("#infoList")[0];
        state = $.data(target, "datagrid");
        opts = state.options;
        opts.queryParams.SearchContains = $("#txtSearchContains").val();
        $("#infoList").datagrid("load", opts.queryParams);
    });
</script>